﻿
using hentity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace hwms {
    /**
   *┌────────────────────────────────────────────────┐
   *│　描    述：ParamFacade                                                    
   *│　作    者：sgj                                              
   *│　版    本：1.0                                              
   *│　创建时间：2021/9/19 8:49:00                        
   *└────────────────────────────────────────────────┘
   **/
    public class TaskParamFacade {
        List<ParamRelation> prList = new List<ParamRelation>();
        Dictionary<long ,ParamRelation> prDict = new Dictionary<long ,ParamRelation>();
        public TaskParamFacade(List<CoreTaskParam> list) {
            createRelation(list);
            initRelation();
            foreach( ParamRelation pr in prList ) {
                pr.deep = pr.getDeep();
            }
        }
        void createRelation(List<CoreTaskParam> list) {
            foreach( CoreTaskParam p in list ) {
                ParamRelation pr = new ParamRelation(p);
                prList.Add(pr);
                prDict.Add(p.id ,pr);
            }
        }

        void initRelation() {
            foreach( ParamRelation pr in prList ) {
                List<long> relyIds = pr.getRelyId();
                foreach( long id in relyIds ) {

                    if( prDict.ContainsKey(id) ) {
                        pr.addRely(prDict[id]);
                    }
                }
            }
        }

        public ParamRelation getDeepest(int stn) {
            ParamRelation res = null;
            foreach( ParamRelation pr in prList ) {
                if( pr.isStn(stn) ) {
                    if( res == null || res.deep < pr.deep ) {

                        res = pr;
                    }
                }

            }
            return res;
        }

    }
}
